
package lab03.test03;

        import java.io.FileInputStream;
        import java.io.FileNotFoundException;
        import java.io.FileOutputStream;
        import java.io.IOException;

/**
 * Created by V555 on 2017/11/30.
 */
public class Test {
    public static void main(String[] args) {
        String path="D:\\test.txt";
        String value="Beijing欢迎你！";
        String value1="我的学号是：1606101057";
        FileOutputStream  fileOutputStream=null;
        try {
            fileOutputStream=new FileOutputStream(path);
            fileOutputStream.write(value.getBytes());
            fileOutputStream.write(value1.getBytes());
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                fileOutputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        //读文件
        FileInputStream fileInputStream=null;
        try {
            fileInputStream=new FileInputStream(path);
            int tmp;
            while ((tmp=fileInputStream.read())!=-1){

                System.out.print((char)tmp);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                fileInputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

